package com.github.server.core;

import androidx.collection.ArraySet;

import com.github.livebase.util.base.CollectionsUtil;
import com.github.livebase.util.base.ObjectsUtil;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName HttpRequest
 * @description:
 * @author: biao532
 * @create: 2024-01-31 22:08
 * @Version 1.0
 **/
public class HttpRequest implements com.github.server.interfaces.HttpRequest {
    private String path;
    private String method;
    private Map<String, String> params;
    private Map<String, String> httpHeaders;

    public HttpRequest(String path, String method, Map<String, String> params, Map<String, String> httpHeaders) {
        this.path = path;
        this.method = method;
        this.params = params;
        this.httpHeaders = httpHeaders;
    }

    public void setHttpHeaders(Map<String, String> httpHeaders) {
        this.httpHeaders = httpHeaders;
    }

    public void setMethod(String method) {
        this.method = method;
    }

    public void setParameters(Map<String, String> params) {
        this.params = params;
    }

    public void setPath(String path) {
        this.path = path;
    }

    @Override
    public String getHeader(String key) {
        if (httpHeaders == null) {
            return null;
        }
        return httpHeaders.get(key);
    }

    @Override
    public String getPath() {
        return path;
    }

    @Override
    public String getParameter(String key) {
        if (params == null) {
            return null;
        }
        return params.get(key);
    }

    @Override
    public String getMethod() {
        return method;
    }

    @Override
    public Set<String> parameterKeySet() {
        if (params == null) {
            return null;
        }
        return new ArraySet<>(params.keySet());
    }

    @Override
    public String toString() {
        return "HttpRequest{" +
                "path='" + path + '\'' +
                ", method='" + method + '\'' +
                ", params=" + params +
                ", httpHeaders=" + httpHeaders +
                '}';
    }
}
